

var newer = newer || {};
newer.gd = newer.gd || {};

newer.PostsDiv = function(o) {
	this.domNode = o.domNode;
	
	this.init();
}

newer.PostsDiv.prototype = {
	
	init: function() {
		this.domNode.html("");
		this.refresh();
	},
	
	refresh: function() {
		
		this.update();
	},
	
	update: function() {
		this.domNode.html("");
		switch(newer.gd.pstatus.ptype) {
			case newer.UriHelper.PEOPLE_TYPE:
				this.showPeoplePosts();
				break;
			case newer.UriHelper.CIRCLE_TYPE:
				this.showCirclePosts();
				break;
			default:
		}
		
	},
	
	showPeoplePosts: function() {
		var self = this;
		var posts = "";
		$.post("/Posts/getPostsByUserId", {pid:newer.gd.people.id}, function(result) {
			if (result["error"] != undefined) {
				// do nothing
			} else {
				$.each(result, function(index, post) {
					self.domNode.append('<div id="profile-post-display-'+post.id+'"></div>');
					new newer.PostDisplay({
						domNode:$("#profile-post-display-"+post.id),
						idSuffix:post.id,
						postInfo:post
					});
				});
			}			
		}, "json");	
	},
	
	showCirclePosts: function() {
		var self = this;
		var posts = "";
		//$.debug("pid is "+gdata.people.id);
		$.post("/Posts/getPostsByCircleId", {cid:newer.gd.circle.id}, function(result) {
			
		}, "json");	
	}
}
